package com.gdpa.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gdpa.entity.BrokerBuildingWithAreaName;
import com.gdpa.entity.BrokerHouse;
import com.gdpa.entity.BrokerHouseWithName;
import com.gdpa.entity.vo.ResponseData;
import com.gdpa.service.IBrokerHouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 经纪房源表 前端控制器
 * </p>
 *
 * @author zsr
 * @since 2018-12-19
 */
@RestController
@RequestMapping("/broker-house")
public class BrokerHouseController {
    @Autowired
    private IBrokerHouseService iBrokerHouseService;

    @RequestMapping("/getHouse")
    public ResponseData getHouse(Page page){
        List<BrokerHouse> list = iBrokerHouseService.getHouse(page);
        return ResponseData.okPage(page.getTotal(),list);
    }

    @RequestMapping("/deleteById/{id}")
    public ResponseData deleteById(@PathVariable("id") Integer id){
        boolean isSuccess = iBrokerHouseService.deleteById(id);
        if(isSuccess)
            return ResponseData.okMsg("删除成功！");
        return ResponseData.failMsg("删除失败!");
    }

    @RequestMapping("/add")
    public ResponseData add(BrokerHouseWithName brokerHouseWithName){
        boolean isSuccess = iBrokerHouseService.add(brokerHouseWithName);
        if(isSuccess)
            return ResponseData.okMsg("添加成功！");
        return ResponseData.failMsg("添加失败!");
    }

    @RequestMapping("/update")
    public ResponseData update(BrokerHouseWithName brokerHouseWithName){
        boolean isSuccess = iBrokerHouseService.update(brokerHouseWithName);
        if(isSuccess)
            return ResponseData.okMsg("修改成功！");
        return ResponseData.failMsg("修改失败!");
    }

    @RequestMapping("/find")
    public ResponseData find(Page page,Integer id, Integer price,Integer state){
        List<BrokerHouseWithName> list = iBrokerHouseService.find(page,id,price,state);
        return ResponseData.okPage(page.getTotal(),list);
    }




    @RequestMapping("/getBuildingName")
    public ResponseData getBuildingName(Integer id){
        String name = iBrokerHouseService.getBuildingName(id);
        return ResponseData.okData(name);
    }

    @RequestMapping("/getUserName")
    public ResponseData getUserName(Integer id){
        String name = iBrokerHouseService.getUserName(id);
        return ResponseData.okData(name);
    }

}
